//
//  KDDataStorage.m
//  iOSKdUser
//
//  Created by WYC on 2017/12/27.
//  Copyright © 2017年 KD. All rights reserved.
//

#import "DataManage.h"
#import "NSObject+Tool.h"
@implementation DataManage

+(void)saveObject:(id)object forKey:(NSString *)key
{
    if (object == nil) {
        [self deleteObjectForKey:key];
    }
    
    [[NSUserDefaults standardUserDefaults] setObject:object forKey:key];
    [[NSUserDefaults standardUserDefaults] synchronize];
}


+(void)saveDicAllObjectWithKey:(NSDictionary *)dic
{
    for (NSString *key in [dic allKeys]) {
        if ([[dic objectForKey:key] isKindOfClass:[NSNull class]]) {
            continue;
        }
        if ([[dic objectForKey:key] isKindOfClass:[NSDictionary class]]) {
            [self saveDicAllObjectWithKey:[dic objectForKey:key]];
        }else
        {
            [self saveObject:[dic objectForKey:key] forKey:key];

        }
    }
}

+(id)getObjectForKey:(NSString *)key
{
    id object = [[NSUserDefaults standardUserDefaults] objectForKey:key];
    if ([object isKindOfClass:[NSData class]]) {
        return object;
    }
    return [NSObject checkStringNull:[[NSUserDefaults standardUserDefaults] objectForKey:key]];
}

+(void)deleteObjectForKey:(NSString *)key
{
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:key];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+(void)clearAllObject
{
    NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
    
    [[NSUserDefaults standardUserDefaults]removePersistentDomainForName:appDomain];
    [[NSUserDefaults standardUserDefaults] synchronize];
    [self saveObject:@1 forKey:@"hasLaunched"];

}

+(BOOL)isLoged
{
    return YES;
}



@end
